<?php
defined('APP_ROOT') or define('APP_ROOT', dirname(__DIR__));
defined('BACKEND_THEME') or define('BACKEND_THEME', 'kzo');

$params = array_merge(
    require __DIR__ . '/../../common/config/params.php',
    require __DIR__ . '/../../common/config/params-local.php',
    require __DIR__ . '/params.php',
    require __DIR__ . '/params-local.php'
);

$config = [
    'id' => 'app-backend',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'backend\controllers',
    'language' => 'zh-CN',
    'modules' => require(__DIR__ . '/modules.php'),
    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
    'params' => $params,
    // "aliases" => [
    //     "@kzo/rbac" => "@vendor/kzo/yii2-rbac",
    // ],
    // 'as access' => [
    //     'class' => 'kzo\rbac\components\AccessControl',
    //     'allowActions' => [
    //         'user/security/login',
    //         'user/security/logout',
    //         'debug/*',
    //         'gii/*',
    //         // '*'
    //     ],
    // ],
    'components' => [
        'request' => [
            'class' => 'common\components\Request',
            'noCsrfRoutes' => [
                'eshop/cashapply/default/cash-apply',
                'activity/record/record/send-money',
                'eshop/custom-service/allowance-form',
                'eshop/custom-service/audit-succ'
            ],
            'csrfParam' => '_csrf-api',
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'DB0uq8cLjtKgh6YYwm4cEZmXEQNrTZav',
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
            ]
        ],
        'formatter' => [
            'dateFormat' => 'Y-M-d',
        ],
        'authManager' => [
            // 'class' => 'dektrium\rbac\components\DbManager', // or use 'yii\rbac\DbManager'
            'class' => 'yii\rbac\DbManager',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'session' => [
            // this is the name of the session cookie used for login on the backend
            'name' => 'advanced-backend',
        ],
        'user' => [
            'class' => 'backend\models\User',
            'identityClass' => 'backend\models\c2\entity\BeUser',
            'enableAutoLogin' => true,
            'identityCookie' => [
                'name' => '_identity-backend',
                'httpOnly' => true
            ],
        ],
        // 'view' => [
        //     'theme' => [
        //         'basePath' => '@app/themes/' . BACKEND_THEME,
        //         'baseUrl' => '@web/themes/' . BACKEND_THEME,
        //         'pathMap' => [
        //             '@app/views' => ['@app/themes/' . BACKEND_THEME,],
        //             '@app/modules' => '@app/themes/' . BACKEND_THEME . '/modules', // module's theme
        //             '@app/widgets' => '@app/themes/' . BACKEND_THEME . '/widgets', // widget's theme
        //         ],
        //     ],
        // ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                'backendLog' => [
                    'class' => 'yii\log\FileTarget',
                    'logFile' => "@runtime/logs/backend_info.log",
                    'categories' => ['application'],
                    'levels' => ['info', 'trace'],
                    // belows setting will keep the log fresh
                    'maxFileSize' => 0,
                    'maxLogFiles' => 0,
                ],
                'backendSql' => [
                    'class' => 'yii\log\FileTarget',
                    'logFile' => "@runtime/logs/backend_sql.log",
                    'categories' => ['yii\db\*'],
                    'levels' => ['info'],

                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => false,
            'rules' => require(__DIR__ . '/seo.php'),
        ],
    ],
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        'allowedIPs' => ['*'],
        'generators' => [ //here
            'crud' => [ // generator name
                'class' => 'yii\gii\generators\crud\Generator', // generator class
                'templates' => [ //setting for out templates
                    '[KZO] TPL-Default' => '@yii/gii/generators/crud/mp-default', // template name => path to template
                    '[KZO] TPL-Popup' => '@yii/gii/generators/crud/mp-popup',
                    'Yii Default' => '@yii/gii/generators/crud/default', // template name => path to template
                ]
            ],
            'controller' => ['class' => 'yii\gii\generators\controller\Generator'],
            'form' => ['class' => 'yii\gii\generators\form\Generator'],
            'extension' => ['class' => 'yii\gii\generators\extension\Generator'],
            'model' => ['class' => 'yii\gii\generators\model\Generator'],
        ],
    ];
}

return $config;